﻿using System;
using System.Collections.Generic;
using System.Data;

namespace BLL.Room
{
		/// <summary>
	/// 业务逻辑类ROOM_EQUIPMENTSUPSUB 的摘要说明。
	/// </summary>
	public class ROOM_EQUIPMENTSUPSUB
	{
		private readonly OracleDAL.Room.ROOM_EQUIPMENTSUPSUB dal=new OracleDAL.Room.ROOM_EQUIPMENTSUPSUB();
		public ROOM_EQUIPMENTSUPSUB()
		{}
		#region  成员方法
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string LOGICEQUIPMENTID,string UPLOGICEQUMENTID)
		{
			return dal.Exists(LOGICEQUIPMENTID,UPLOGICEQUMENTID);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(Model.Room.ROOM_EQUIPMENTSUPSUB model)
		{
			dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public void Update(Model.Room.ROOM_EQUIPMENTSUPSUB model)
		{
			dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public void Delete(string LOGICEQUIPMENTID,string UPLOGICEQUMENTID)
		{
			
			dal.Delete(LOGICEQUIPMENTID,UPLOGICEQUMENTID);
		}
            /// <summary>
        /// 删除一个逻辑设备
      /// </summary>
      /// <param name="LOGICEQUIPMENTID">逻辑设备ID</param>
        public void DeleteLogicEquip(string LOGICEQUIPMENTID)
        {
            dal.DeleteLogicEquip(LOGICEQUIPMENTID);
        }
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.Room.ROOM_EQUIPMENTSUPSUB GetModel(string LOGICEQUIPMENTID,string UPLOGICEQUMENTID)
		{
			
			return dal.GetModel(LOGICEQUIPMENTID,UPLOGICEQUMENTID);
		}
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.Room.ROOM_EQUIPMENTSUPSUB GetModel(string LOGICEQUIPMENTID)
        {

            return dal.GetModel(LOGICEQUIPMENTID);
        }
        ///// <summary>
        ///// 得到一个对象实体，从缓存中。
        ///// </summary>
        //public Model.Room.ROOM_EQUIPMENTSUPSUB GetModelByCache(string LOGICEQUIPMENTID,string UPLOGICEQUMENTID)
        //{
			
        //    string CacheKey = "ROOM_EQUIPMENTSUPSUBModel-" + LOGICEQUIPMENTID+UPLOGICEQUMENTID;
        //    object objModel = LTP.Common.DataCache.GetCache(CacheKey);
        //    if (objModel == null)
        //    {
        //        try
        //        {
        //            objModel = dal.GetModel(LOGICEQUIPMENTID,UPLOGICEQUMENTID);
        //            if (objModel != null)
        //            {
        //                int ModelCache = LTP.Common.ConfigHelper.GetConfigInt("ModelCache");
        //                LTP.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
        //            }
        //        }
        //        catch{}
        //    }
        //    return (Model.Room.ROOM_EQUIPMENTSUPSUB)objModel;
        //}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Model.Room.ROOM_EQUIPMENTSUPSUB> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.Room.ROOM_EQUIPMENT> GetModelListCom(string strWhere)
        {
            DataSet ds = dal.GetListCom(strWhere);
            return DataTableToListCom(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetDataSetCom(string strWhere)
        {
           return dal.GetListCom(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.Room.ROOM_EQUIPMENT> GetModelListCom(string strWhere, string TABLENAME)
        {
            DataSet ds = dal.GetListCom(strWhere, TABLENAME);
            return DataTableToListCom(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet  GetDataSetCom(string strWhere, string TABLENAME)
        {
            return dal.GetListCom(strWhere, TABLENAME);
        }
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Model.Room.ROOM_EQUIPMENTSUPSUB> DataTableToList(DataTable dt)
		{
			List<Model.Room.ROOM_EQUIPMENTSUPSUB> modelList = new List<Model.Room.ROOM_EQUIPMENTSUPSUB>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Model.Room.ROOM_EQUIPMENTSUPSUB model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new Model.Room.ROOM_EQUIPMENTSUPSUB();
					model.LOGICEQUIPMENTID=dt.Rows[n]["LOGICEQUIPMENTID"].ToString();
					model.UPLOGICEQUMENTID=dt.Rows[n]["UPLOGICEQUMENTID"].ToString();
					model.EQUIPTYPE=dt.Rows[n]["EQUIPTYPE"].ToString();
					if(dt.Rows[n]["CREATETIME"].ToString()!="")
					{
						model.CREATETIME=DateTime.Parse(dt.Rows[n]["CREATETIME"].ToString());
					}
					model.CREATEUSERISN=dt.Rows[n]["CREATEUSERISN"].ToString();
					if(dt.Rows[n]["MODIFYTIME"].ToString()!="")
					{
						model.MODIFYTIME=DateTime.Parse(dt.Rows[n]["MODIFYTIME"].ToString());
					}
					model.MODIFYUSERISN=dt.Rows[n]["MODIFYUSERISN"].ToString();
					model.EQUIPMENTID=dt.Rows[n]["EQUIPMENTID"].ToString();
					model.EQUIPMENT_PERF=dt.Rows[n]["EQUIPMENT_PERF"].ToString();
					model.ISMONITORALARM=dt.Rows[n]["ISMONITORALARM"].ToString();
					model.ISMONITORPERF=dt.Rows[n]["ISMONITORPERF"].ToString();
					if(dt.Rows[n]["ORDERINDEX"].ToString()!="")
					{
						model.ORDERINDEX=int.Parse(dt.Rows[n]["ORDERINDEX"].ToString());
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.Room.ROOM_EQUIPMENT> DataTableToListCom(DataTable dt)
        {
            List<Model.Room.ROOM_EQUIPMENT> modelList = new List<Model.Room.ROOM_EQUIPMENT>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.Room.ROOM_EQUIPMENT model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.Room.ROOM_EQUIPMENT();
                    model.LOGICEQUIPMENTID = dt.Rows[n]["LOGICEQUIPMENTID"].ToString();
                    model.UPLOGICEQUMENTID = dt.Rows[n]["UPLOGICEQUMENTID"].ToString();
                    model.EQUIPTYPE = dt.Rows[n]["EQUIPTYPE"].ToString();
                    model.EQUIPMENTID = dt.Rows[n]["EQUIPMENTID"].ToString();
                    model.EQUIPMENT_PERF = dt.Rows[n]["EQUIPMENT_PERF"].ToString();
                    model.ISMONITORALARM = dt.Rows[n]["ISMONITORALARM"].ToString();
                    model.ISMONITORPERF = dt.Rows[n]["ISMONITORPERF"].ToString();
                    if (dt.Rows[n]["ORDERINDEX"].ToString() != "")
                    {
                        model.ORDERINDEX = int.Parse(dt.Rows[n]["ORDERINDEX"].ToString());
                    }
                    model.LOGICEQUIPMENTNAME = dt.Rows[n]["LOGICEQUIPMENTNAME"].ToString();
                    model.EQUIPMENTPROPERTY = dt.Rows[n]["EQUIPMENTPROPERTY"].ToString();
                    if (dt.Rows[n]["TOP"].ToString() != "")
                    {
                        model.TOP = int.Parse(dt.Rows[n]["TOP"].ToString());
                    }
                    if (dt.Rows[n]["LEFT"].ToString() != "")
                    {
                        model.LEFT = int.Parse(dt.Rows[n]["LEFT"].ToString());
                    }
                    //model.REMARK = dt.Rows[n]["REMARK"].ToString();
                    //model.TXTCONTENT = dt.Rows[n]["TXTCONTENT"].ToString();
                    //model.TXTPROPERTY = dt.Rows[n]["TXTPROPERTY"].ToString();
                    model.TYPE = dt.Rows[n]["TYPE"].ToString();
                    modelList.Add(model);
                }
            }
            return modelList;
        }

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}
        public string GetJsonStr(string strWhere, string TABLENAME)
        {
            string strJson = string.Empty;
            DataSet ds = dal.GetListCom(strWhere, TABLENAME);
            if (ds != null&&ds.Tables [0].Rows .Count >0) {
                DBUtility.DataSetHelper dsh = new DBUtility.DataSetHelper();
                string tmpStr = string.Empty;
                DataTable dt = dsh.SelectDistinct("tb", ds.Tables[0], "TYPE");
                int length = dt.Rows.Count;
                for (int i = 0; i < length; i++)
                {
                    tmpStr = dt.Rows[i]["TYPE"].ToString();
                    if (i == 0) {
                        strJson += "\"" + tmpStr + "\":[";
                    }
                    else
                    {
                        strJson += ",\"" + tmpStr + "\":[";
                    }
                    DataRow[] dr = ds.Tables[0].Select("TYPE='" + tmpStr + "'");
                    int count = dr.Length;
                    for (int j = 0; j < count; j++)
                    {
                        strJson += "{\"id\":\"" + dr[j]["LOGICEQUIPMENTID"].ToString() + "\",\"name\":\"" + dr[j]["LOGICEQUIPMENTNAME"].ToString() + "\",";
                        strJson += "\"left\":\"" + dr[j]["LEFT"].ToString() + "px\",\"top\":\"" + dr[j]["TOP"].ToString() + "px\",\"status\":\"0\",";
                        strJson += "\"type\":\"" + dr[j]["EQUIPTYPE"].ToString() + "\",\"equipid\":\"" + dr[j]["EQUIPMENTID"].ToString() + "\",\"isReal\":\"" + dr[j]["ISMONITORPERF"].ToString() + "\",";
                        strJson += "\"property\":{" + dr[j]["EQUIPMENTPROPERTY"].ToString() + "}";
                        if (j < count - 1)
                        {
                            strJson += "},";
                        }
                        else
                        {
                            strJson += "}]";
                        }
                    }
                }
                return strJson;
            }
            else
            {
                return string.Empty;
            }
        }
		/// <summary>
		/// 获得数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  成员方法
	}
}

